package SquarePackage;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import java.math.BigDecimal;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import Border.Door;
import Border.Wall;



/**
 * Een testklasse voor de klasse Square.
 * Deze bevat alle testmethoden om setters en speciale mutators
 * te controleren van de klasse 'transparant vakje'.
 * 
 * @author      Nathan Bekaert & Philippe de Potter de ten Broeck
 * @version 1.0
 */
public class TransparentSquareTest {

	private TransparentSquare transparant1;
	private  TransparentSquare transparant2;
	private TransparentSquare transparant3;
	private TransparentSquare transparant4;
	private TransparentSquare transparant5;
	private TransparentSquare square;


	@Before
	public void setUp() throws Exception {
		Door door = new Door(transparant1,Direction.EAST);
		transparant1 = new TransparentSquare(0,BigDecimal.ZERO,TemperatureScale.CELSIUS,door,Direction.EAST);
		transparant2 = new TransparentSquare(0, BigDecimal.valueOf(10),TemperatureScale.CELSIUS, Direction.WEST, true);
		transparant3 = new TransparentSquare(0,new BigDecimal(50.00),TemperatureScale.CELSIUS, Direction.NORTH, false);
		square = new TransparentSquare();
		transparant5 = new TransparentSquare(0,BigDecimal.ZERO);
	}



	//Random testing, actually only important thing is that all the constructors work

	@Test
	public void testColdDamage()throws Exception{
		transparant1.setTemperature(new Temperature(20));
		assertEquals(transparant1.coldDamage(), 0);
		transparant1.setTemperature(new Temperature(-16));
		assertEquals(transparant1.coldDamage(), 1);
		transparant1.setTemperature(new Temperature(-91));
		assertEquals(transparant1.coldDamage(), 8);
	}
	@Test
	public void testHeatDamage()throws Exception{
		transparant1.setTemperature(20);
		assertEquals(0,transparant1.heatDamage());
		transparant1.setTemperature(118);
		assertEquals(5,transparant1.heatDamage());
	}
	@Test
	public final void constructorStandard(){
		assertEquals(1, square.numberOfBorders(square.getBorders()));
	}

	@Test
	public final void constructorStandardSouth(){
		Square testSquare = new TransparentSquare(0,BigDecimal.ZERO,TemperatureScale.CELSIUS,Direction.SOUTH,false);
		assertEquals(1, testSquare.amountOfDoors());
		assertEquals(1, testSquare.numberOfBorders(testSquare.getBorders()));
		assertTrue(testSquare.hasBorder(Direction.SOUTH));
	}

	@Test (expected = IllegalArgumentException.class)
	public final void constructorStandardIllegalFloor(){
		Square testSquare = new TransparentSquare(0,BigDecimal.ZERO,TemperatureScale.CELSIUS,Direction.CEILING,false);
	}

	@Test
	public final void constructorLegalCase(){
		Square testSquare = new TransparentSquare(0,BigDecimal.ZERO,TemperatureScale.CELSIUS,Direction.EAST,true);
		assertEquals(2, testSquare.amountOfDoors());
		assertEquals(2, testSquare.numberOfBorders());
		assertTrue(testSquare.hasBorder(Direction.EAST));
		assertTrue(testSquare.hasBorder(Direction.WEST));
	}


	@Test
	public final void canHaveAsBorderNoDoorOppositeDirection(){
		Square testSquare = new TransparentSquare(0, BigDecimal.ZERO,TemperatureScale.CELSIUS,Direction.NORTH,false);
		assertTrue(testSquare.canHaveAsBorder( new Door(testSquare, Direction.SOUTH),Direction.SOUTH));
	}

	@Test
	public final void canHaveAsBorderDoorSameDirection(){
		Square testSquare = new TransparentSquare(0, BigDecimal.ZERO,TemperatureScale.CELSIUS,Direction.SOUTH,false);
		assertTrue(testSquare.canHaveAsBorder(new Door(testSquare, Direction.NORTH),Direction.NORTH));
	}

	@Test	(expected = IllegalArgumentException.class)
	public final void canHaveAsBorderDoorOppositeDirection(){
		Square testSquare = new TransparentSquare(0, BigDecimal.ZERO,TemperatureScale.CELSIUS,Direction.SOUTH,true);
		assertFalse(testSquare.canHaveAsBorder(new Door(testSquare, Direction.SOUTH),Direction.SOUTH));
		assertFalse(testSquare.canHaveAsBorder(new Door(testSquare, Direction.WEST),Direction.WEST));
	}

}